from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon, QPalette, QBrush, QPixmap
from PyQt5.QtWidgets import QApplication, QDialog, QHBoxLayout, QVBoxLayout
import sys
import matplotlib
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.backends.backend_template import FigureCanvas
from matplotlib.figure import Figure
import numpy as np
import cv2
from PIL import Image
import os
import matplotlib.pyplot as plt

#处理墙体数据
def bin2img(bin_data):
    img_data = np.frombuffer(bin_data,dtype=np.uint8).reshape(101,611)
    f = open("wall_01.txt",'w+')
    for i in range(0, 101):
        print(img_data[i])
        f.write(str(img_data[i]) + '\n')
    f.close()
    row = 101
    column = 611
    xarray = []
    yarray = []
    for i in range(0, row):
        for j in range(0, column):
            if (img_data[i][j] == 1):
                xarray.append(round((i - 51) * 0.1, 2))  #保留两位小数
                yarray.append(round(j * 0.1, 2))
    return xarray,yarray

f = "1" + ".txt"
radar_wall_data_file = open(f, 'r')

radar_list = radar_wall_data_file.readlines()
# print(radar_list)
radar_list = ''.join(radar_list).strip('\n')

print((bytes().fromhex(radar_list)).hex())
    # c.send(bytes().fromhex(radar_list[i]))
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1) # 画1行1列个图形的第1个
radar_wall_data_file.close()

wall_list_x,wall_list_y = bin2img(bytes().fromhex(radar_list))
print(wall_list_x)
print(wall_list_y)

ax1.plot(wall_list_x, wall_list_y, 'g.')

ax1.set_xlim(-10, 10)
ax1.set_ylim(0, 60)
ax1.legend()
plt.show()

